package com.yedean.factory.config;

import com.yedean.factory.ConfigurableBeanFactory;
import com.yedean.factory.property.PropertyValues;
import lombok.Data;

/**
 * BeanDefinition bean定义
 *
 * @author yedean
 * @date 2022/6/28
 */

@Data
public class BeanDefinition {

    String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;

    String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;

    private Class<?> beanClass;
    private PropertyValues propertyValues;
    
    private String initMethodName;
    
    private String destroyMethodName;

    private String scope = SCOPE_SINGLETON;

    private boolean singleton = true;

    private boolean prototype = false;
    
    public BeanDefinition(Class<?> beanClass) {
        this.beanClass = beanClass;
        this.propertyValues=new PropertyValues();
    }

    public BeanDefinition(Class<?> beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = propertyValues != null ? propertyValues : new PropertyValues();
    }


    public void setScope(String beanScope) {
        this.scope = beanScope;
        this.singleton = SCOPE_SINGLETON.equals(beanScope);
        this.prototype = SCOPE_PROTOTYPE.equals(beanScope);
    }
}
